﻿
const PHINECOS_C = Components;
const PHINECOS_HELLOWORLD_CONTRACTID = "@mydomain.com/XPCOMSample/MyComponent;1"
var gHelloWorldSvc = null;

// This is the main function
function helloWorld()
{
    try
    {
        alert("准备创建组件");
        gHelloWorldSvc = PHINECOS_C.classes[PHINECOS_HELLOWORLD_CONTRACTID].createInstance(PHINECOS_C.interfaces.IMyComponent);//创建实例
        if(gHelloWorldSvc!=null)
        {
            alert("创建组件成功");
            gHelloWorldSvc = gHelloWorldSvc.QueryInterface(PHINECOS_C.interfaces.IMyComponent);
        }
        else
        {
            alert("创建组件失败");
            return;
        }    
        var res = gHelloWorldSvc.Add(3, 4);
        alert('Performing 3+4. Returned ' + res + '.');
        alert("创建结束");
    }
    catch(ex)
    {
        alert("error");
    }
}
